/* Receipts.do */

* Global options.
global OUTREG2OPTIONS tex(fragment) 2aster auto(2) rdec(3) label
global TABLELOC "."
global FE_options fe cluster(Party_State)

use "Receipts.dta", clear

*
* tsset Diff in diff by party-state-year.
*
tsset Party_State cycle, delta(2)

*****************************
* Regression models
*****************************

* Loop over different specifications.
forvalues modelgroups = 1(1)2 {
  * Determine specification.
	if `modelgroups'==1 {
    * My coding of less_costly and nonpartisan.
    local EVs = "less_costly_primary nonpartisan_primary"
    local outregfile "$TABLELOC/Table05"
    local note "Excluded category is institutions most costly for individual participation."
  }
  else if `modelgroups'==2 {
    * Original McGheet et al. coding. Closed excluded.
    local EVs = "ptype_*"
    local outregfile "$TABLELOC/TableA07"
    local note "Excluded category is closed primary."
  }

  local keepvars "`EVs'"
  xtreg total_receipts `EVs' i.cycle, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Candidate,Receipts,(1000s)") sdec(0) addnote("OLS coefficients with robust standard errors clustered on state-party in parentheses.", "Money dependent variables in thousands of dollars.","`note'") nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") replace
  * Log version.
  xtreg log_total_receipts `EVs' i.cycle, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Log,Receipts") sdec(2) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
  * Percentage change.
  foreach var of varlist `EVs' {
    di "Estimated percentage change of `var':" _n 100*(exp(_b[`var'])-1)
  }

  * Number donors.
  xtreg num_givers `EVs' i.cycle, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Count of, Contributors") sdec(0) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
  * Log version.
  xtreg log_num_givers `EVs' i.cycle, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Log,Count, Contributors") sdec(2) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
   
  * Percent of total receipts to incumbents in non-open races.
  xtreg incum_pct_receipts `EVs' i.cycle, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Percent, Receipts To, Incumbent") sdec(1) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
   
  * Percent of total receipts to winners of primaries.
  xtreg prim_winner_pct_receipts `EVs' i.cycle, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Percent Receipts,To Primary,Winners") sdec(1) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
   
}

* Summary statistics.
summ total_receipts, detail
summ num_givers, detail
